﻿Ext.define("PSI.OutPlan.ChangeDispatcherForm", {
    createUI: function (entity) {
        var me = this;

        var wnd = Ext.create("Ext.window.Window", {
            title: "更改调度",
            modal: true,
            onEsc: Ext.emptyFn,
            width: 500,
            height: 150,
            layout: "fit",
            items: [
                {
                    id: "editForm",
                    xtype: "form",
                    layout: "form",
                    height: "100%",
                    bodyPadding: 5,
                    defaultType: 'textfield',
                    fieldDefaults: {
                        labelWidth: 60,
                        labelAlign: "right",
                        labelSeparator: "",
                        msgTarget: 'side'
                    },
                    items: [
                        {
                            xtype: "hidden",
                            name: "idList",
                            value: entity.idList
                        }, {
                            id: "editDispatcher",
                            name: "dispatcher",
                            fieldLabel: "调度",
                            allowBlank: false,
                            blankText: "没有输入调度",
                            beforeLabelTextTpl: PSI.Const.REQUIRED,
                            xtype: "psi_bc_dispatcherfield"
                        }
                    ],
                    buttons: [
                        {
                            text: "确定",
                            formBind: true,
                            iconCls: "psi-button-ok",
                            handler: me.onOK,
                            scope: me
                        },
                        {
                            text: "取消", handler: function () {
                                PSI.MsgBox.confirm("请确认是否取消操作?", function () {
                                    me.wnd.close();
                                });
                            }, scope: me
                        }
                    ]
                }
            ]

        });

        me.wnd = wnd;
    },

    show: function (parentForm, entity) {
        var me = this;

        me.parentForm = parentForm;

        me.createUI(entity);

        me.wnd.on("show", function () { me.onEditFormShow(entity); }, me);

        me.wnd.show();
    },

    onEditFormShow: function (entity) {
        Ext.getCmp("editDispatcher").focus();
    },

    // private
    onOK: function () {
        var me = this;

        var f = Ext.getCmp("editForm");
        var el = f.getEl() || Ext.getBody();
        el.mask("数据保存中...");
        f.submit({
            url: "/OutPlan/ChangeDispatcher",
            method: "POST",
            success: function (form, action) {
                el.unmask();
                me.wnd.close();
                me.parentForm.refreshPlanGrid();
            },
            failure: function (form, action) {
                el.unmask();
                PSI.MsgBox.showInfo(action.result.msg, function () {
                    Ext.getCmp("editDispatcher").focus();
                });
            }
        });
    }
});